package com.qfjy.controller.homeWork917.liubingjian;

/**
 * @Author lbj
 * @Date 2021-09-17 10:53
 */
//观察者的实现类
public class MyTopicSubscriber implements Observer{

    private String name;
    private Subject topic;
    public MyTopicSubscriber(String nm){
        this.name=nm;
    }
    //观察者对目标类改变做出的反应
    @Override
    public void update() {
        String msg = (String) topic.getUpdate(this);
        if(msg == null){
            System.out.println(name+":: No new message");
        }else
        System.out.println(name+":: Consuming message::"+msg);

    }

    @Override
    public void setSubject(Subject sub) {
        this.topic=sub;
    }
}
